////////////////////////////////////////////////
// DESCRIPTION:
//    MSHelp2 registration Custom Action
//
// Legal Notices:
//   Copyright (c) 2008, Telliam Consulting, LLC.
//   All rights reserved.
//
//   Redistribution and use in source and binary forms, with or without modification,
//   are permitted provided that the following conditions are met:
//
//   * Redistributions of source code must retain the above copyright notice, this list
//     of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above copyright notice, this
//     list of conditions and the following disclaimer in the documentation and/or other
//     materials provided with the distribution.
//   * Neither the name of Telliam Consulting nor the names of its contributors may be
//     used to endorse or promote products derived from this software without specific
//     prior written permission.
//
//   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
//   EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
//   SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
//   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
//   BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
//   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
//   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
//   DAMAGE. 
//
#include "stdafx.h"
#include "RegHelp2CA.h"

class ComInit
{
public:
    ComInit() { ::CoInitialize(NULL); }
    ~ComInit() { ::CoUninitialize(); }
};
static ComInit StaticInit;

#ifdef _DEBUG
void DebugEntry() { ::MessageBox(NULL, _T( "Attatch to me!" ), _T("Attach2Me"), MB_OK); }
#else 
#define DebugEntry()
#endif

using namespace FusionWare::MSI;

// Exported Custom Actions
extern "C"
{
    // group = immediate actions

    UINT __stdcall RegisterHelp(MSIHANDLE hInstall)
    {
        DebugEntry();        
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::RegisterHelp>());
    }

    UINT __stdcall UnregisterHelp(MSIHANDLE hInstall)
    {
        DebugEntry();        
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::UnregisterHelp>());
    }

    // group = Deferred actions

    UINT __stdcall StartTransaction( MSIHANDLE hInstall )
    {
        DebugEntry();        
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::StartTransaction>());
    }

    UINT __stdcall RegisterNamespaces( MSIHANDLE hInstall )
    {
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::RegisterNamespaces>());
    }

    UINT __stdcall RegisterHelpFiles( MSIHANDLE hInstall )
    {
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::RegisterHelpFiles>());
    }

    UINT __stdcall PluginHelpCollections( MSIHANDLE hInstall )
    {
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::PluginHelpCollections>());
    }

    UINT __stdcall UnregisterNamespaces( MSIHANDLE hInstall )
    {
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::UnregisterNamespaces>());
    }

    UINT __stdcall UnregisterHelpFiles( MSIHANDLE hInstall )
    {
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::UnregisterHelpFiles>());
    }

    UINT __stdcall UnplugHelpCollections( MSIHANDLE hInstall )
    {
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::UnplugHelpCollections>());
    }

    UINT __stdcall RollbackTransaction( MSIHANDLE hInstall )
    {
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::RollbackTransaction>());
    }

    UINT __stdcall CommitTransaction( MSIHANDLE hInstall )
    {
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::CommitTransaction>());
    }

    UINT __stdcall MergeIndices( MSIHANDLE hInstall )
    {
        RegHelp2CASession session(hInstall);
        return session.DoCustomAction( session.GetAction<&RegHelp2CASession::MergeIndices>());
    }
}